/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.myapp.struts;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Usuario
 */
@Entity
@Table(name = "PESSOA")
@NamedQueries({@NamedQuery(name = "PessoaPersistente.findByCpf", 
        query = "SELECT p FROM PessoaPersistente p WHERE p.cpf = :cpf"), 
@NamedQuery(name = "PessoaPersistente.findByNome",
        query = "SELECT p FROM PessoaPersistente p WHERE p.nome = :nome"), 
@NamedQuery(name = "PessoaPersistente.findByEmail", 
        query = "SELECT p FROM PessoaPersistente p WHERE p.email = :email"),
@NamedQuery(name = "PessoaPersistente.findBySenha", 
        query = "SELECT p FROM PessoaPersistente p WHERE p.senha = :senha"), 
@NamedQuery(name = "PessoaPersistente.findByEhadmin", 
        query = "SELECT p FROM PessoaPersistente p WHERE p.ehadmin = :ehadmin")})
public class PessoaPersistente implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "CPF", nullable = false)
    private Integer cpf;
    @Column(name = "NOME", nullable = false)
    private String nome;
    @Column(name = "EMAIL")
    private String email;
    @Column(name = "SENHA", nullable = false)
    private String senha;
    @Column(name = "EHADMIN", nullable = false)
    private int ehadmin;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cpfDono")
    private Collection<AgendaPersistente> agendaPersistenteCollection;
    @JoinColumn(name = "LOCALIZACAO", referencedColumnName = "ID_LOC")
    @ManyToOne
    private LocalizacaoPersistente localizacao;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cpfDono")
    private Collection<VeiculosPersistente> veiculosPersistenteCollection;

    public PessoaPersistente() {
    }

    public PessoaPersistente(Integer cpf) {
        this.cpf = cpf;
    }

    public PessoaPersistente(Integer cpf, String nome, String senha, int ehadmin) {
        this.cpf = cpf;
        this.nome = nome;
        this.senha = senha;
        this.ehadmin = ehadmin;
    }

    public Integer getCpf() {
        return cpf;
    }

    public void setCpf(Integer cpf) {
        this.cpf = cpf;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    public int getEhadmin() {
        return ehadmin;
    }

    public void setEhadmin(int ehadmin) {
        this.ehadmin = ehadmin;
    }

    public Collection<AgendaPersistente> getAgendaPersistenteCollection() {
        return agendaPersistenteCollection;
    }

    public void setAgendaPersistenteCollection(Collection<AgendaPersistente> agendaPersistenteCollection) {
        this.agendaPersistenteCollection = agendaPersistenteCollection;
    }

    public LocalizacaoPersistente getLocalizacao() {
        return localizacao;
    }

    public void setLocalizacao(LocalizacaoPersistente localizacao) {
        this.localizacao = localizacao;
    }

    public Collection<VeiculosPersistente> getVeiculosPersistenteCollection() {
        return veiculosPersistenteCollection;
    }

    public void setVeiculosPersistenteCollection(Collection<VeiculosPersistente> veiculosPersistenteCollection) {
        this.veiculosPersistenteCollection = veiculosPersistenteCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (cpf != null ? cpf.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PessoaPersistente)) {
            return false;
        }
        PessoaPersistente other = (PessoaPersistente) object;
        if ((this.cpf == null && other.cpf != null) || (this.cpf != null && !this.cpf.equals(other.cpf))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.myapp.struts.PessoaPersistente[cpf=" + cpf + "]";
    }

}
